﻿using System;
using System.Collections.Generic;
using System.Text;
using Cabal.Kernel.DataSet;

namespace Cabal.Kernel.Output
{
    /// <summary>
    /// 保存任务的集合
    /// </summary>
    public class MissionCollection : List<Mission>
    {
        public MissionCollection() : base() { }
        public MissionCollection(int capacity) : base(capacity) { }
        public MissionCollection(IEnumerable<Mission> collection) : base(collection) { }

        public List<Mission> SelectPair(string key, string value)
        {
            List<Mission> rtv = new List<Mission>();
            foreach (Mission i in this)
                if (i.Data.FlagSet.Select(key, value))
                    rtv.Add(i);
            return rtv;
        }
        public List<Mission> SelectPair(params string[] pairs)
        {
            List<Mission> rtv = new List<Mission>();
            foreach (Mission i in this)
                if (i.Data.SelectPair(pairs))
                    rtv.Add(i);
            return rtv;
        }
        public List<Mission> SelectPair(CLKeyValuePair[] pairs)
        {
            List<Mission> rtv = new List<Mission>();
            foreach (Mission i in this)
                if (i.Data.SelectPair(pairs))
                    rtv.Add(i);
            return rtv;
        }
        public List<Mission> SelectExps(params string[] exps)
        {
            List<Mission> rtv = new List<Mission>();
            foreach (Mission i in this)
                if (i.Data.SelectExp(exps))
                    rtv.Add(i);
            return rtv;
        }

        public void GcByTime(List<Mission> m, int time)
        {
            for (int i = m.Count - 1; i >= 0; i--)
            {
                if (m[i].Data.NeedCollect(time))
                {
                    this.Remove(m[i]); //集合里的去除
                    m.RemoveAt(i); //参数中 列表里的去除
                }
            }
        }
    }
}
